import {
  AndroidOutlined,
  SkypeOutlined,
  FontSizeOutlined,
  HeatMapOutlined,
  AreaChartOutlined,
} from '@ant-design/icons-vue'
import { icon } from './icon.ts'
import { RouteRecordRaw } from 'vue-router'
// 任意路由
const anyRoute: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/constant/login.vue'),
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/constant/error.vue'),
  },
  {
    path: '/:catchAll(.*)', //匹配未定义的路由
    redirect: '/404', //重定向
  },
]
// 菜单路由
export const menuRoute: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'layout',
    component: () => import('@/components/layout/index.vue'),
    children: [
      {
        path: 'home',
        name: 'home',
        meta: {
          title: '首页',
          icon: icon.HomeOutlined,
        },
        component: () => import('@/views/home/home.vue'),
      },
      {
        path: 'chat',
        name: 'chat',
        meta: {
          title: '人工智能',
          icon: AndroidOutlined,
        },
        component: () => import('@/views/chat/index.vue'),
      },
      {
        path: 'image',
        name: 'image',
        meta: {
          title: '壁纸大全',
          icon: icon.SettingOutlined,
        },
        children: [
          {
            path: 'image360',
            name: 'image360',
            meta: {
              title: '360壁纸',
            },
            component: () => import('@/views/images/image360/index.vue'),
          },
          {
            path: 'imagesNet',
            name: 'imagesNet',
            meta: {
              title: '壁纸集',
            },
            component: () => import('@/views/images/imagesNet/index.vue'),
          },
          {
            path: 'bing',
            name: 'bing',
            meta: {
              title: 'bing图库',
            },
            component: () => import('@/views/images/bing/index.vue'),
          },
          {
            path: 'baidu',
            name: 'baidu',
            meta: {
              title: '百度图源',
            },
            component: () => import('@/views/images/baidu/index.vue'),
          },
          {
            path: 'mohu',
            name: 'mohu',
            meta: {
              title: '萌虎壁纸',
            },
            component: () => import('@/views/images/MoHu/index.vue'),
          },
        ],
      },
      {
        path: 'news',
        name: 'news',
        meta: {
          title: '热搜合集',
          icon: SkypeOutlined,
        },
        children: [
          {
            path: 'HotSearchCollectionOne',
            name: 'HotSearchCollectionOne',
            meta: {
              title: '热搜合集(少)',
            },
            component: () =>
              import('@/views/news/HotSearchCollectionOne/index.vue'),
          },
          {
            path: 'HotSearchCollectionTwo',
            name: 'HotSearchCollectionTwo',
            meta: {
              title: '热搜合集(多)',
            },
            component: () =>
              import('@/views/news/HotSearchCollectionTwo/index.vue'),
          },
          {
            path: 'local',
            name: 'local',
            meta: {
              title: '新闻合集',
            },
            component: () => import('@/views/news/localNews/index.vue'),
          },
        ],
      },
      {
        path: 'others',
        name: 'others',
        meta: {
          title: '其它',
          icon: FontSizeOutlined,
        },
        children: [
          {
            path: 'video',
            name: 'video',
            meta: {
              title: '精选视频',
            },
            component: () => import('@/views/others/video/index.vue'),
          },
          {
            path: 'goldPrice',
            name: 'goldPrice',
            meta: {
              title: '黄金价格',
            },
            component: () => import('@/views/others/goldPrice/index.vue'),
          },
          {
            path: 'weather',
            name: 'weather',
            meta: {
              title: '天气查询',
            },
            component: () => import('@/views/others/weather/index.vue'),
          },
          {
            path: 'yule',
            name: 'yule',
            meta: {
              title: '娱乐',
            },
            component: () => import('@/views/others/yule/index.vue'),
          },
          {
            path: 'earthquake',
            name: 'earthquake',
            meta: {
              title: '地震查询',
            },
            component: () => import('@/views/others/earthquake/index.vue'),
          },
          {
            path: 'manysFn',
            name: 'manysFn',
            meta: {
              title: '常用功能',
            },
            component: () => import('@/views/others/manysFn/index.vue'),
          },
        ],
      },
      {
        path: 'screen',
        name: 'screen',
        meta: {
          title: '可视化',
          icon: AreaChartOutlined,
        },
        children: [
          {
            path: 'border',
            name: 'border',
            meta: {
              title: 'E-DATAV',
            },
            component: () => import('@/views/screen/border.vue'),
          },
          {
            path: 'fastUI',
            name: 'fastUI',
            meta: {
              title: 'fast-dataview-ui',
            },
            component: () => import('@/views/screen/fastUI.vue'),
          },
          {
            path: 'bigScreen',
            name: 'bigScreen',
            meta: {
              title: '数据大屏',
            },
            redirect: '/big',
          },
          {
            path: 'vtable',
            name: 'vtable',
            meta: {
              title: '高性能表格',
            },
            component: () => import('@/views/screen/vtable.vue'),
          },
        ],
      },
      {
        path: 'otherFunctions',
        name: 'otherFunctions',
        meta: {
          title: '其他功能',
          icon: HeatMapOutlined,
        },
        component: () => import('@/views/otherFunctions/index.vue'),
      },
      {
        path: 'setRoute',
        name: 'setRoute',
        meta: {
          title: '路由权限管理',
          icon: icon.SettingOutlined,
        },
        component: () => import('@/views/setRoute/index.vue'),
      }
    ],
    beforeEnter: (to, from, next) => {
      console.log(to.path);
      if (to.path === '/home') {
        let initPath = localStorage.getItem('ProductPath');
        if (!initPath || initPath === '/') {
          initPath = '/home';
        }
        // 检查是否需要跳转到相同的路径
        if (to.path !== initPath) {
          next({ path: initPath });
        } else {
          next(); // 如果已经是目标路径，则直接放行
        }
      } else {
        next();
      }
    },
    redirect: '/home'
  }
]
// 一级路由
const oneRoute: Array<RouteRecordRaw> = [
  {
    path: '/imgDetail',
    name: 'imgDetail',
    component: () => import('@/views/images/image360/detail.vue'),
  },
  {
    path: '/big',
    name: 'big',
    component: () => import('@/views/screen/bigScreen.vue'),
  },
]
export const constantRoute: Array<RouteRecordRaw> = [
  //...menuRoute,
  ...anyRoute,
  ...oneRoute,
]
